<template>
	<view class="contents" :style="'height:'+screenHeight+'px;'">
		<view class="bodys">
			<view class="none" v-if="show">
				<view class="coent">
					<u-empty v-if="showtext===false" text="请提交评价" mode="list" icon-size="200">
					</u-empty>
					<u-empty v-if="showtext===true" text="您已提交过满意度评价" mode="list" icon-size="200"></u-empty>

				</view>
			</view>
			<view class="conent" v-else>
				<view class="header">
					<span>门诊患者征求意见表</span>
				</view>
				<view class="" style="padding: 10rpx;">
					<view>尊敬的患者朋友，您好!</view>
					<view>&emsp;为了解我院为您的服务情况，进一步加强医院管理，改善就医环境，不断提高医疗服务质量，请您认真填写本调查表，您只需在每个问题相应选项内打“√”或提出宝贵意见，谢谢!</view>
				</view>

				<view class="jianyi">

					<u-field v-model="Dpt" label="就诊科室" placeholder="请填写就诊科室">
					</u-field>
					<u-field v-model="JzDoc" label="接诊医生" placeholder="请填写接诊医生">
					</u-field>
					<u-field type="number" v-model="Age" label="年龄" placeholder="请填写年龄">

					</u-field>

					<view class=""
						style="display: flex;align-items: center;padding-left: 4.5%;height:45px;border-bottom: 1px solid #f3f3f3; /* 实线灰色线条 */">
						性别
						<view class="" style="padding-left: 80rpx;">
							<u-radio-group v-model="Sex" @change="radioGroupChange2">
								<u-radio @change="radioChange" v-for="(item, index) in listt2" :key="index"
									:name="item.name" :disabled="item.disabled">
									{{item.name}}
								</u-radio>
							</u-radio-group>
						</view>




					</view>

				</view>


				<view class="neiorng">
					<view class="datalist" v-for="(item,index) in datalist" :key="index">
						<view class="list">
							<span style="color: red;">*&nbsp;</span>
							<span style="font-weight: bold;">{{item.ProTempCode}}.&nbsp;</span>
							<span>{{item.ProTemContent}}</span>
						</view>
						<!-- @tap="ssss(index)" -->
						<view class="listb">
							<u-radio-group v-model="wjtx[index].value">
								<u-radio v-for="(itema, indexa) in wjtx[index].lists" @change="radioGroupChange"
									:key="indexa" :name="itema.name">
									{{itema.name}}
								</u-radio>
							</u-radio-group>
						</view>

					</view>
					<view class="listb">
						<view class="">
							您愿意介绍其他病人来本院看病吗?
							<u-radio-group v-model="value" @change="radioGroupChange2" style="margin-left: 5rpx;">
								<u-radio @change="radioChange" v-for="(item, index) in listt" :key="index"
									:name="item.name" :disabled="item.disabled">
									{{item.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
					<view class="jianyi">
						<view style="margin-bottom: 10rpx;">您对我院医生/护士有何意见及建议:</view>
						<u-input v-model="jianyival" border type="textarea" />
					</view>
					<view class="jianyi">
						<view style="margin-bottom: 10rpx;">您对我院服务于群众的意见建议:</view>
						<u-input v-model="Cotents" border type="textarea" />
					</view>
					<view class="jianyi">
						<view style="margin-bottom: 10rpx;">&emsp;为方便进一步改进工作，请留下联系方式:
						</view>
						<u-field v-model="phone" label="电话" placeholder="请填写电话">
						</u-field>

					</view>

					<view style="width: 100%;display: flex;justify-content: center;padding:40rpx;">
						<view class="submit">
							<u-button type="primary" @click="submit">提交</u-button>
						</view>
					</view>

				</view>

			</view>

		</view>
		<u-modal v-if="doctorshow" v-model="show2" title="预约挂号条款" confirm-color='#55aaff'
			:title-style="{ fontWeight: 'bold'}" confirm-text="前往就诊人管理" :show-cancel-button="false" @confirm="confirm"
			:mask-close-able="false">
			<view class="slot-content">

				<view class="" style="padding: 20px;">
					<view class="" style="text-align: center;">

					</view>
					<view class="">
						当前暂无就诊人，请前往就诊人管理页面添加就诊人。
					</view>
				</view>

			</view>
		</u-modal>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from 'vuex'

	export default {
		data() {
			return {
				showtext: false,
				name: '',
				JzDoc: '',
				phone: '',
				show: true,
				show2: true,
				Dpt: '',
				jianyival: '',
				screenHeight: getApp().globalData.screenHeight - 44,
				datalist: '',
				wjtx: [],
				Age: '',
				Sex: '',
				text: '',
				IsShow: "",
				mode: 'date',
				Cotents: '',
				doctorshow: false,
				listt: [{
						name: '是',
						disabled: false
					},
					{
						name: '否',
						disabled: false
					}

				],
				listt2: [{
						name: '男',
						disabled: false
					},
					{
						name: '女',
						disabled: false
					}

				],
				value: '',

			}
		},
		computed: {
			...mapState(['token'], ['userInfo']),
			...mapGetters(['hasLogin', 'getUserInfo'])
		},

		onLoad() {

			if (this.hasLogin) {
				// uni.showLoading({
				// 	title: '加载中'
				// })

				this.$store.dispatch('getUserInfo');
			
				this.mrjzr()



			} else {
				
				uni.hideLoading();
				uni.showModal({
					title: '提示',
					content: '登录后才可以操作',
					confirmText: '去登录',
					showCancel: false,
					success: function(res) {
						uni.navigateTo({
							url: '/pages/auth/login?name=myddc'
						})
					}
				});
				return;
			}

		},
		methods: {
			confirm() {
				this.redirectToBindCard()
				uni.setStorageSync("URL", "/pages/menzhenmanyidu/myddc")


			},
			redirectToBindCard() {
				const hospitalId = '40119';
				const redirectUri = 'http://xncdwx.xztongyong.cn/h5/#/pages/MedicalExamination/Healthcard/Healthcard';
				const bindCardUrl = this.constructBindCardUrl(hospitalId, redirectUri);
				window.location.href = bindCardUrl;
			},
			constructBindCardUrl(hospitalId, redirectUri) {
				const baseUrl = "https://h5-health.tengmed.com/h5/tencent/open/card/regist";
				const encodedRedirectUri = encodeURIComponent(redirectUri);
				let bindCardUrl = `${baseUrl}?hospitalId=${hospitalId}&redirect_uri=${encodedRedirectUri}`;
				return bindCardUrl;
			},
			ssss(index) {
				console.log("满意度问题", index)
				if (this.text != '') {
					this.wjtx[index].value = this.text
				}
				console.log("wjtx", this.wjtx)
			},
			pinkProDetails() {

				let temp3 = {
					prodetail: ''

				}
				let temp = []

				// let temp = `{"prodetail":[`
				for (let i = 0; i < this.wjtx.length; i++) {

					let le
					switch (this.wjtx[i].value) {
						case '非常满意':
							le = 10;
							break
						case '满意':
							le = 8;
							break
						case '一般':
							le = 6;
							break
						case '不满意':
							le = 0;
							break
					}

					temp.push({
						ProTempId: this.datalist[i].ProTempId,
						PF: le
					});





				}
				console.log(temp)
				temp3.prodetail = temp
				// temp = temp + `]}`

				return JSON.stringify(temp3)

			},
			mrjzr() {

				this.$request("patient", "defaultInfo").then(res => {
					console.log(res.code)
					if (res.code == 1) {
						if (res.data) {
							this.name = res.data.Name
							this.showtext = true
							this.list()
						} else {
							this.doctorshow = true
							this.showtext = false
						}

					} else {
						this.doctorshow = true
						this.showtext = false
					}
				})
			},
			submit() {




				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				let sum = 0
				let item = this.wjtx
				console.log(this.wjtx)
				for (let i = 0; i < item.length; i++) {
					if (item[i].value == '非常满意') {
						sum += 10
					} else if (item[i].value == '满意') {
						sum += 8
					} else if (item[i].value == '一般') {
						sum += 6
					} else {
						sum += 0
					}
				}


				let ProDetails = this.pinkProDetails();
				console.log("总分", sum)
				//return
				this.$request("ProblemTem", "Submit", {

					Content: this.jianyival,
					ProDetails: ProDetails,
					ZPF: sum,
					Name: this.name,
					Phone: this.phone,
					Work: "",
					Protype: 1,
					Dpt: this.Dpt,
					JzDoc: this.JzDoc,
					Age: this.Age,
					Sex: this.Sex,
					Cotents: this.Cotents,
					IsShow: this.value
				}).then(res => {
					console.log("提交满意度问题", res)
					if (res.code == 1) {
						this.show = true
						uni.hideLoading();
						uni.switchTab({
							url: `/pages/index/index`,

						})
					} else {
						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			},
			radioChange(e) {
				console.log(e);
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log(e);
				this.text = e
				console.log("wsat", this.wjtx)

			},
			radioGroupChange3(e) {
				console.log(e);
				this.text = e
				console.log("wsat", this.wjtx)

			},
			radioGroupChange3(e) {
				console.log(e);
				this.text = e
				console.log("wsat", this.wjtx)

			},
			list() {
				uni.showLoading({
					title: '请稍后',
					mask: true
				});
				this.$request("ProblemTem", "List", {
					protype: 1


				}).then(res => {
					// console.log("满意度问题", res)
					console.log(res)
					if (res.code == 1) {
						this.datalist = res.data
						this.wjtx = []
						let objet = {
							lists: [{
									name: '非常满意',
									value: 10
								},
								{
									name: '满意',
									value: 8
								},
								{
									name: '一般',
									value: 6
								}, {
									name: '不满意',
									value: 0
								},
							],
							value: '非常满意'
						}
						for (let i = 0; i < res.data.length; i++) {
							this.wjtx[i] = JSON.parse(JSON.stringify(objet))
						}
						console.log("this.wjtx", this.wjtx)
						console.log("this.datalist", this.datalist)
						this.show = false
						uni.hideLoading();

					} else {
						this.show = true


						uni.hideLoading();
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				}).catch(err => {
					this.show = true

					uni.hideLoading();
					console.log("err", err)
					uni.showToast({
						title: err,
						icon: 'none',
						duration: 1000
					});
				});
			}
		}
	}
</script>

<style>
	@import './myddc.css';
</style>